var username = tool.getCookie('username')
// 判断是否登录
if(!username){
    layer.msg('请先登录',{
        icon:2,
        time:1500
    },function(){
        localStorage.setItem('url',location.href)
        location.href = "../html/login.html"
    })
}

// 加载层 - 防止加载图片效果影响用户体验感
// 加载层
var loadindex = layer.load(1,{
    shade:[1,"#000"]
})
var pageSize = 20
$.get('../php/list.php',res=>{
    console.log(res);
    // 加载好数据
    var {meta:{status,msg},data} = res;
    if(status === 1){
        new Page('fenye',{
            pageData:{
                total:data.length,
                pageSize
            },
            show:function(currentPage){
                var arr = data.slice((currentPage-1)*pageSize,currentPage*pageSize)
                var str = '';
                
                for(var i=0;i<arr.length;i++){
                    str += `
                        
                    <div class="row">
                        <a href="../html/detail.html?id=${arr[i].id}">
                            <img class="pic" src="${arr[i].imgpath.split('==========')[0]}" alt="...">
                            <div class="caption h3">
                                <h3>${arr[i].name}</h3>
                            </div>
                        </a>
                    </div>
                               
                    `
                }
                $('.goods').html(str)
            }
        })
        
        
    }
    layer.close(loadindex)
},'json')